package com.lzj.servlet;

import com.lzj.dao.UserDao;
import com.lzj.dao.impl.UserDaoImpl;
import com.lzj.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @autor:lzj
 * @date:2021/12/3
 */
public class UpdateAddress extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String recipients=req.getParameter("recipients");
        String fullAddress=req.getParameter("fullAddress");
        String postcode=req.getParameter("postcode");
        String phoneNumber=req.getParameter("phoneNumber");
        int userId=(int)req.getSession().getAttribute("userId");
        UserServiceImpl userService = new UserServiceImpl();
        UserDao userDao = new UserDaoImpl();
        userService.setUserDao(userDao);
        com.lzj.entity.Address address=new com.lzj.entity.Address(recipients,fullAddress,postcode,phoneNumber,userId);
        int result = userService.updateAddress(address);
        if(result>0){
            com.lzj.entity.Address address1 = userDao.queryAddress(userId);
            req.getSession().setAttribute("address",address);//重新给session的address键赋值
            resp.sendRedirect("/user_center_site.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
